package com.sunny.l10;

public class Solution {
    public boolean hasCycle(ListNode head) {

        ListNode p1 = head;
        if(null == p1)
            return false;
        ListNode p2 = p1.next;
        if(null == p2)
            return false;

        while (null != p2){

            p1 = p1.next;

            p2 = p2.next;
            if(null == p2)
                return false;
            p2 = p2.next;

            if(p1 == p2)
                return true;

        }

        return false;

    }
}

class ListNode {
    int val;
    ListNode next;
    ListNode(int x) {
      val = x;
      next = null;
    }
 }